//
//  CYRuleView.m
//  CaiYun
//
//  Created by 今日信息科技 on 2017/7/19.
//  Copyright © 2017年 今日信息科技. All rights reserved.
//

#import "CYRuleView.h"
@interface CYRuleView(){
    updateBlock _myblock;
}
@property (nonatomic, strong) CYLabel *exampleLBL;
@property (nonatomic, strong) CYLabel *ruleLBL;
@property (nonatomic, strong) CYLabel *example_contentLBL;
@property (nonatomic, strong) CYLabel *rule_contentLBL;
@end
@implementation CYRuleView
- (instancetype)initWithColor:(UIColor *)color updateBounds:(updateBlock)block{
    self = [super initWithColor:color];
    if (self) {
        _myblock = block;
        self.exampleLBL.hidden = self.ruleLBL.hidden = NO;
        self.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH, CGRectGetHeight(_exampleLBL.bounds) + CGRectGetHeight(_ruleLBL.bounds) + AL(PT(24)) * 4);
        
    }
    return self;
}
//示例
- (CYLabel *)exampleLBL{
    if (!_exampleLBL) {
        _exampleLBL = [[CYLabel alloc]initWithText:@"示例" size:AL(PT(26)) textcolor:THEME_COLOR];
        [self addSubview:_exampleLBL];
        
        [_exampleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self).with.offset(AL(PT(24)));
            make.left.equalTo(self).with.offset(AL(PT(24)));
            make.size.mas_equalTo(_exampleLBL.bounds.size);
        }];
    }
    return _exampleLBL;
}
//中奖说明
- (CYLabel *)ruleLBL{
    if (!_ruleLBL) {
        _ruleLBL = [[CYLabel alloc]initWithText:@"中奖说明" size:AL(PT(26)) textcolor:THEME_COLOR];
        [self addSubview:_ruleLBL];
        
        [_ruleLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_exampleLBL.mas_bottom).with.offset(AL(PT(24)) * 2);
            make.left.equalTo(self).with.offset(AL(PT(24)));
            make.size.mas_equalTo(_ruleLBL.bounds.size);
        }];
    }
    return _ruleLBL;
}
//示例内容
- (CYLabel *)example_contentLBL{
    if (!_example_contentLBL) {
        _example_contentLBL = [[CYLabel alloc]initWithText:_exampleStr size:AL(PT(26)) textcolor:ColorHex(0x333333)];
        _example_contentLBL.numberOfLines = 0;
        [self addSubview:_example_contentLBL];
        
        [_example_contentLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_exampleLBL.mas_bottom).with.offset(AL(PT(12)));
            make.left.equalTo(self).with.offset(AL(PT(24)));
            make.size.mas_equalTo([_example_contentLBL autoSizeWithWidth:(SCREEN_WIDTH - AL(PT(24)))]);
        }];
    }
    return _example_contentLBL;
}


//中奖说明内容
- (CYLabel *)rule_contentLBL{
    if (!_rule_contentLBL) {
        _rule_contentLBL = [[CYLabel alloc]initWithText:_ruleStr size:AL(PT(26)) textcolor:ColorHex(0x333333)];
        _rule_contentLBL.numberOfLines = 0;
        [self addSubview:_rule_contentLBL];
        
        [_rule_contentLBL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_ruleLBL.mas_bottom).with.offset(AL(PT(12)));
            make.left.equalTo(self).with.offset(AL(PT(24)));
            make.size.mas_equalTo([_rule_contentLBL autoSizeWithWidth:(SCREEN_WIDTH - AL(PT(24)))]);
        }];
    }
    return _rule_contentLBL;
}

- (void)setRuleStr:(NSString *)ruleStr{
    if (_ruleStr != ruleStr)
        _ruleStr = ruleStr;
    self.rule_contentLBL.text = ruleStr;
    [self updateBoundsForRule_ContentLBL];
}

- (void)setExampleStr:(NSString *)exampleStr{
    if (_exampleStr != exampleStr)
        _exampleStr = exampleStr;
    self.example_contentLBL.text = exampleStr;
    [self updateBoundsForExemple_ContentLBL];
}

//示例内容
- (void)updateBoundsForExemple_ContentLBL{
    
    CGSize size = [_example_contentLBL autoSizeWithWidth:(SCREEN_WIDTH - AL(PT(24)))];
    _example_contentLBL.bounds = CGRectMake(0.0, 0.0, ceil(size.width), size.height);
    
    [_example_contentLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(_example_contentLBL.bounds.size);
    }];
    
    [_ruleLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_exampleLBL.mas_bottom).with.offset(AL(PT(24)) * 1.5 + _example_contentLBL.bounds.size.height);
    }];
    [self updateBoundsForSelf];
    
}

//中奖说明内容
- (void)updateBoundsForRule_ContentLBL{
    
    CGSize size = [_rule_contentLBL autoSizeWithWidth:(SCREEN_WIDTH - AL(PT(24)))];
    _rule_contentLBL.bounds = CGRectMake(0.0, 0.0, ceil(size.width), size.height);
    
    [_rule_contentLBL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_ruleLBL.mas_bottom).with.offset(AL(PT(12)));
        make.size.mas_equalTo(_rule_contentLBL.bounds.size);
    }];
    
    [self updateBoundsForSelf];
}

- (void)updateBoundsForSelf{
    
    CGFloat height = ceil( CGRectGetHeight(_exampleLBL.bounds) + CGRectGetHeight(_example_contentLBL.bounds) + CGRectGetHeight(_ruleLBL.bounds) + CGRectGetHeight(_rule_contentLBL.bounds) + AL(PT(24)) * 4);
    self.bounds = CGRectMake(0.0, 0.0, SCREEN_WIDTH, height);
    
    //    [self mas_updateConstraints:^(MASConstraintMaker *make) {
    //        make.size.mas_equalTo(self.bounds.size);
    //    }];
    
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
